package com.zw.gulimall.search.controller;

import com.zw.common.menu.BizCodeEnum;
import com.zw.common.to.es.SkuEsModel;
import com.zw.common.utils.R;
import com.zw.gulimall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/search/save")
public class ElasticSearchController {

    @Autowired
    private ProductSaveService productSaveService;

    //    商家商品
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        Boolean res = false;
        try {
            res = productSaveService.statusUp(skuEsModels);

        } catch (Exception e) {
            log.error("ElasticSearchController商品商家异常:{}", e.getMessage());
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
        if (res) {
            return R.ok();
        } else {
            return R.error();
        }
    }
}
